package utils;

import java.io.BufferedReader;
import java.io.FilterReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class TranscationReader extends FilterReader {

    public TranscationReader(BufferedReader br) {
        super(br);
    }

    public String[] readTx() throws IOException {
        String[] line;
        String buf;

        StringTokenizer st;
        BufferedReader br = (BufferedReader) in;
        buf = br.readLine();
        while (buf != null) {
            st = new StringTokenizer(buf, " ");
            //区分是生成交易，还是监听到的转发
            if(buf.contains("trans_create") ){
                line = new String[4];
               line[0]=st.nextToken();
               line[1]=st.nextToken().replace("+08:00","");
               line[2]=st.nextToken().replace("from:", "");
               line[3]=st.nextToken().replace("tx:", "");
            }else if(buf.contains("listen_tx")) {
                line = new String[5];
                line[0] = st.nextToken();
                line[1] = st.nextToken().replace("+08:00","");;
                line[2] = st.nextToken().replace("from:", "");
                line[3] = st.nextToken().replace("to:", "");
                line[4] = st.nextToken().replace("tx:", "");
            }else if(buf.contains("node_info")){
                line = new String[3];
                line[0] = st.nextToken();
                line[1] = st.nextToken().replace("node.id:", "");
                line[2] = st.nextToken().replace("isListener:", "");
            }else{
                buf = br.readLine();
                continue;
            }
            return line;
        }
        return null;
    }
}
